<?php
/*
  $Id: treeview.php,v 1.0 10/08/2005 Beer Monster Exp $

  osCommerce, Open Source E-Commerce Solutions
  http://www.oscommerce.com

  Copyright (c) 2003 osCommerce

  Released under the GNU General Public License
*/

  require('includes/application_top.php');

   include(DIR_WS_CLASSES . 'pos_order.php');
   require(DIR_WS_CLASSES . 'currencies.php');
  $currencies = new currencies();

 if (isset($_GET['posID'])){
    $posID = tep_db_prepare_input($_GET['posID']);
    }else if (isset($_POST['posID'])){
      $posID = $_POST['posID'] ;
    } else {
     $posID = '' ;
    }

  $pos = new pos($posID);
  $customer_id = $pos->customer['id'];
   //gets customer group ID
  if($customer_id=="")
  {
    $customer_group_id="G";
  }
  else
  {
    $getcustomer_GroupID_query = tep_db_query("select customers_group_id   from " . TABLE_CUSTOMERS . " where  customers_id = '" . (int)$customer_id . "'");
    $getcustomer_GroupID = tep_db_fetch_array($getcustomer_GroupID_query);
    $customer_group_id=$getcustomer_GroupID['customers_group_id'];
  }

?>
<!doctype html public "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html <?php echo HTML_PARAMS; ?>>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=<?php echo CHARSET; ?>">
  <title><!-- Catalog Tree --><?php echo TREEVIEW_TXT_1;?></title>

<link rel="stylesheet" type="text/css" href="includes/stylesheet.css">
  <script type="text/javascript" src="includes/javascript/dtree.js"></script>

</head>

<body>
<div class="dtree"><form>
<p><a href="javascript: d.openAll();"><!-- open all --><?php echo TREEVIEW_TXT_2;?></a> | <a href="javascript: d.closeAll();"><!-- close all --><?php echo TREEVIEW_TXT_3;?></a></p>
<?php
    $defaultlanguage_query_raw ="SELECT l.languages_id FROM " . TABLE_LANGUAGES . " as l WHERE l.code ='" . DEFAULT_LANGUAGE . "'";
    $defaultlanguage_query = tep_db_query($defaultlanguage_query_raw);
    $defaultlanguage= tep_db_fetch_array($defaultlanguage_query);


echo "<script type='text/javascript'>
    <!--
    d = new dTree('d'); \n
    d.add(0,-1,'Customer','','');\n";

    $customers_query_raw = "SELECT c.customers_id, c.customers_firstname , c.customers_lastname, customers_telephone
    FROM " . TABLE_CUSTOMERS . " c
    ORDER BY c.customers_lastname";

    $customers_query = tep_db_query($customers_query_raw);
    $cust_inital_old = '';
    while ($customers = tep_db_fetch_array($customers_query)) {
      $customers_name = $customers['customers_lastname'] . ', ' .$customers['customers_firstname'];
   //get first char of last name;
    $cust_inital = strtoupper(substr($customers['customers_lastname'], 0, 1));
      //ingnore repreats
      if ($cust_inital_old != $cust_inital){
      //one up number

      echo "d.add(" . tep_convert_let_numb($cust_inital) . "," . '0' . ",'" . addslashes($cust_inital) . "','', '');\n"; //,," . $customers['customers_id'] . ",,,); \n";
      }
      $cust_inital_old = $cust_inital;
    } //end while

    $customers_query_raw_2 = "SELECT c.customers_id, c.customers_firstname , c.customers_lastname, customers_telephone
    FROM " . TABLE_CUSTOMERS . " AS c
     ORDER BY c.customers_lastname";

    $customers_query_2 = tep_db_query($customers_query_raw_2);
    while ($customers_2 = tep_db_fetch_array($customers_query_2)) {
          $customers_name_2 = $customers_2['customers_lastname'] . ', ' .$customers_2['customers_firstname'];

          $cust_inital_2 = strtoupper(substr($customers_2['customers_lastname'], 0, 1));
       // if ($cust_inital_2 == $cust_inital) {
       echo "d.add(" . $customers_2['customers_id'] . "0000," . tep_convert_let_numb($cust_inital_2) .",'" . addslashes($customers_name_2) . "','', '<input type=checkbox name=customers onClick=cycleCheckboxes(this.form) value=" . $customers_2['customers_id'] . ">');\n"; //,," . $customers_2['customers_id'] . ",,,); \n";
      // }
    }//end while

?>
document.write(d);

    //-->
  </script>
 <?php
 echo '<b>Select only one Customer </b><br>';
 ;?>

<INPUT TYPE="BUTTON" onClick="cycleCheckboxes(this.form)" VALUE="Select Customer"></form>
<script type='text/javascript'>
    <!--
function cycleCheckboxes(what) {

window.opener.document.update_customer.update_customer_customers_id.value ="";

 for (var i = 0; i<what.elements.length; i++) {
        if ((what.elements[i].name.indexOf('customers') > -1)) {
            if (what.elements[i].checked) {
                window.opener.document.update_customer.update_customer_customers_id.value += what.elements[i].value;
            }
        }
    }
window.close();
}
    //-->
</script>
</div>
</body>

</html>
